/*****************************************************************************
*
* File: hw_init.h
*
* Description: Header file for hw_init.c
*
* Author: Kevin Casteel, Luis Castillo
*
* Revisions: v-1.0 (4/18/11)
*
******************************************************************************/
#ifndef _HW_INIT_H
#define _HW_INIT_H

#define ALL          0xFF
#define NONE         0x00
#define MS6          0xFC
#define BAUD         0x17

#define MSB          0x80
#define LEFT         0x6B
#define RIGHT        0x74
#define UP           0x75
#define DOWN         0x72

#define NORTH        0x60
#define SOUTH        0x06
#define EAST         0x11
#define WEST         0x88
#define HEAVEN       0xF0
#define HELL         0x0F

#define FIRSTLAYER 	 	4
#define SECONDLAYER     8
#define THIRDLAYER	   16
#define FOURTHLAYER    32
#define FIFTHLAYER	   64
#define SIXTHLAYER 	  128
#define CUBEHEIGHT	 	6
#define CUBEWIDTH	 	4
#define CUBELENGTH	 	4
#define MAXSNAKELENGTH  6

#define FAST          250
#define SUPERFAST      50

#define DELAY        2000

//Structure for holding the individual 
//layer's lighting settings
typedef struct layer {
	uint8_t leds[4][4];
} layer_t;

//Structure for holding the current cube 
//lighting settings
typedef struct cube {
	layer_t layers[6];
} cube_t;

//Structure for holding the current location
//of the snake's head
typedef struct location {
	uint8_t layer;
	uint8_t row;
	uint8_t col;
} location_t;


/************************************************ 
 *
 * Function: vInit_HW()
 *
 * Description: Initializes ports.
 *
 ************************************************/
void vInit_HW();

/************************************************ 
 *
 * Function: xFindLED()
 *
 * Description: Finds LED that needs to be ON.
 *
 * Return: bit value that needs to be asserted.
 *
 ************************************************/
uint8_t xFindLED(uint8_t pos);


/************************************************ 
 *
 * Function: vInit_Test()
 *
 * Description: Tests every LED.
 *
 ************************************************/
void vInit_Test();


/************************************************ 
 *
 * Function: USART_Init()
 *
 * Description: Initializes USART port.
 *
 ************************************************/
void vUSART_Init();


/************************************************ 
 *
 * Function: xUSART_Receive()
 *
 * Description: Receives data from USART.
 *
 * Return: Received data from buffer.
 *
 ************************************************/
uint8_t xUSART_Receive();



/************************************************ 
 *
 * Function: vLeds()
 *
 * Description: Display value to top layer of
 *              LEDs.
 *
 * Parameters: data - value to be displayed
 *
 ************************************************/
void vLeds(uint8_t data);


/************************************************ 
 *
 * Function: vReadKB()
 *
 * Description: Reads arrow keys on keyboard.
 *
 ************************************************/
void vReadKBTask(void *pvParameters);


/************************************************ 
 *
 * Function: vMotionTask()
 *
 * Description: Calls function to move and
 *              display snake.
 *
 ************************************************/
void vMotionTask(void *pvParameters);


/************************************************ 
 *
 * Function: vSetCubeLighting()
 *
 * Description: Illuminates the cube according to 
 *				the data stored in current.
 *
 * Param: current - current cube status.
 *
 * Return: Received data from buffer.
 *
 ************************************************/
void vSetCubeLighting(cube_t *current);


/************************************************ 
 *
 * Function: vTranslateLocation()
 *
 * Description: Converts snake's current location 
 *				to the cube so it can be displayed
 *
 * Parameters: current - Pointer to cube.
 *
 ************************************************/
 void vTranslateLocation(cube_t *current);


/************************************************ 
 *
 * Function: vClearCube()
 *
 * Description: Clears contents of cube.
 *
 * Parameters: cube - Pointer to cube.
 *
 ************************************************/
void vClearCube(cube_t *cube);


/************************************************ 
 *
 * Function: vInitSnake()
 *
 * Description: Initializes length of snake.
 *
 * Parameters: location - initial location of
 *                        snake's head.
 *
 ************************************************/
void vInitSnake(location_t *snake);


/************************************************ 
 *
 * Function: vMoveSnake()
 *
 * Description: Updates de location of the snake.
 *
 ************************************************/
void vMoveSnake(void);


/************************************************ 
 *
 * Function: vGrowSnakeTask()
 *
 * Description: Increases snake length after
 *              a set time.
 *
 ************************************************/
void vGrowSnakeTask(void *pvParameters);


/************************************************ 
 *
 * Function: vCheckDeath()
 *
 * Description: Monitors the Death flag so that
 *				game will end when dead.
 *
 ************************************************/
void vCheckDeath(void);


/************************************************ 
 *
 * Function: vYouDead()
 *
 * Description: Plays animation when game over.
 *
 ************************************************/
void vYouDead(void);


/************************************************ 
 *
 * Function: ISR
 *
 * Description: Services USART RXC interrupt.
 *
 * Parameters: USART_RXC_vect interrupt vector.
 *
 ************************************************/
ISR(USART_RXC_vect);


#endif
